﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Drawing;
using System.Dynamic;
using System.Windows;
namespace WTSQCB
{
    public partial class MonHoc : System.Web.UI.Page
    {
        private string chuoiketnoi = ConfigurationManager.ConnectionStrings["WebDiemTSQCBConnectionString"].ConnectionString;
        protected void Page_Load(object sender, EventArgs e)
        {
            //MaMonHoctxt.Style["Position"] = "inherit";
            //MaMonHoctxt.Style["Left"] = "70px";

            //TenMonHoctxt.Style["Position"] = "static";
            //TenMonHoctxt.Style["Left"] = "70px";

            //STLTtxt.Style["Position"] = "static";
            //STLTtxt.Style["Left"] = "70px";

            //STTHtxt.Style["Position"] = "static";
            //STTHtxt.Style["Left"] = "70px";

            //STTLtxt.Style["Position"] = "static";
            //STTLtxt.Style["Left"] = "70px";

            //STTHoctxt.Style["Position"] = "static";
            //STTHoctxt.Style["Left"] = "70px";

            //SDVHTtxt.Style["Position"] = "static";
            //SDVHTtxt.Style["Left"] = "70px";
            
          
        }

        protected void Thembtn_Click(object sender, EventArgs e)
        {
            try
            {
                SqlConnection con = new SqlConnection(chuoiketnoi);
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = con;
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "MonHocThem";
                cmd.Parameters.AddWithValue("@mamonhoc", MaMonHoctxt.Text);
                cmd.Parameters.AddWithValue("@tenmonhoc", TenMonHoctxt.Text);
                cmd.Parameters.AddWithValue("@sotietlithuyet", STLTtxt.Text);
                cmd.Parameters.AddWithValue("@sotietthuchanh", STTHtxt.Text);
                cmd.Parameters.AddWithValue("@sotietthaoluan", STTLtxt.Text);
                cmd.Parameters.AddWithValue("@sotiettuhoc", STTHoctxt.Text);
                cmd.Parameters.AddWithValue("@sodvht", SDVHTtxt.Text);                
                cmd.Parameters.AddWithValue("@mabomon", BoMonddl.SelectedValue);
                con.Open();
                cmd.ExecuteNonQuery();
                con.Close();
                MonHocdgv.DataBind();
                Response.Write("Thêm thành công");
            }
            catch (Exception ex)
            {
                Response.Write("không thực hiện được");
            }
        }

        protected void Suabtn_Click(object sender, EventArgs e)
        {
            try
            {
                SqlConnection con = new SqlConnection(chuoiketnoi);
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = con;
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "MonHocSua";
                cmd.Parameters.AddWithValue("@mamonhoc", MaMonHoctxt.Text);
                cmd.Parameters.AddWithValue("@tenmonhoc", TenMonHoctxt.Text);
                cmd.Parameters.AddWithValue("@sotietlithuyet", STLTtxt.Text);
                cmd.Parameters.AddWithValue("@sotietthuchanh", STTHtxt.Text);
                cmd.Parameters.AddWithValue("@sotietthaoluan", STTLtxt.Text);
                cmd.Parameters.AddWithValue("@sotiettuhoc", STTHoctxt.Text);
                cmd.Parameters.AddWithValue("@sodvht", SDVHTtxt.Text);                
                cmd.Parameters.AddWithValue("@mabomon", BoMonddl.SelectedValue);
                con.Open();
                cmd.ExecuteNonQuery();
                con.Close();
                MonHocdgv.DataBind();
                Response.Write("Sửa thành công");
            }
            catch
            {
                Response.Write("không thực hiện được");
            }
        }

        protected void Xoabtn_Click(object sender, EventArgs e)
        {
            try
            {
                SqlConnection con = new SqlConnection(chuoiketnoi);
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = con;
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "MonHocXoa";
                cmd.Parameters.AddWithValue("@mamonhoc", MaMonHoctxt.Text);                
                con.Open();
                cmd.ExecuteNonQuery();
                con.Close();
                MonHocdgv.DataBind();
                Response.Write("Xóa thành công");
            }
            catch
            {
                Response.Write("không thực hiện được");
            }
        }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            GridViewRow dong = MonHocdgv.SelectedRow;
            MaMonHoctxt.Text = HttpUtility.HtmlDecode(dong.Cells[1].Text);
            TenMonHoctxt.Text = HttpUtility.HtmlDecode(dong.Cells[2].Text);
            STLTtxt.Text = HttpUtility.HtmlDecode(dong.Cells[3].Text);
            STTHtxt.Text = HttpUtility.HtmlDecode(dong.Cells[4].Text);
            STTLtxt.Text = HttpUtility.HtmlDecode(dong.Cells[5].Text);
            STTHoctxt.Text = HttpUtility.HtmlDecode(dong.Cells[6].Text);
            SDVHTtxt.Text = HttpUtility.HtmlDecode(dong.Cells[8].Text);
                     
        }

        protected void STLTtxt_TextChanged(object sender, EventArgs e)
        {

        }

        protected void STTLtxt_TextChanged(object sender, EventArgs e)
        {

        }

        protected void Khoaddl_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}